const axios = require('axios');

async function testEdgeCases() {
    const testCases = [
        {
            name: '空内容测试',
            content: { title: '空文档', content: '' }
        },
        {
            name: '只有标题测试',
            content: { title: '只有标题的文档', content: '<h1>只有标题</h1>' }
        },
        {
            name: '特殊字符测试',
            content: { 
                title: '特殊字符文档', 
                content: '<p>包含特殊字符：&lt;&gt;&amp;&quot;&#39; 以及中文标点：，。！？；：</p>' 
            }
        },
        {
            name: '嵌套HTML测试',
            content: { 
                title: '嵌套HTML', 
                content: '<p>这是<strong>粗体<em>加斜体</em>文本</strong>和<code>代码</code>混合</p>' 
            }
        },
        {
            name: '长文档测试',
            content: { 
                title: '长文档测试', 
                content: '<p>' + '这是一个很长的段落。'.repeat(200) + '</p>' 
            }
        },
        {
            name: '无效文件名测试',
            content: { title: '包含/无效\\字符*的?文件名', content: '<p>测试文件名清理</p>' }
        }
    ];
    
    console.log('开始测试边缘情况...\n');
    
    for (const testCase of testCases) {
        try {
            console.log(`测试: ${testCase.name}`);
            
            const filename = `${testCase.name}.docx`;
            const response = await axios.post('http://localhost:3002/api/export-to-word', {
                content: testCase.content,
                filename: filename
            });
            
            if (response.data.success) {
                console.log(`✅ ${testCase.name} - 成功`);
            } else {
                console.log(`❌ ${testCase.name} - 失败: ${response.data.error}`);
            }
            
        } catch (error) {
            console.log(`❌ ${testCase.name} - 异常: ${error.response?.data?.error || error.message}`);
        }
    }
    
    console.log('\n边缘情况测试完成！');
}

testEdgeCases();